/*  ------------------------------------------------------------------------  */
/*  Paper        : Does Stakeholder Outrage Determine Executive Pay?          */
/*  Program      : a02-09-governance.do                                       */
/*  Description  : Governance analysis                                        */
/*  ------------------------------------------------------------------------  */

use "$temp112/outragePanel.dta", clear

eststo drop *

/*  ------------------------------------------------------------------------  */
//  Controls

capture drop firm_fe
gen firm_fe = 1

gen f2020 = fyear==2020

rename defer_rpt_as_comp_tot defer_rpt
rename defer_rpt_as_comp_tot_fr defer_rpt_fr

#delimit ;
global compvars
	tdc1 salary varcomp bonus stock_awards_fv option_awards_fv
	noneq_incent othcomp defer_rpt
; #delimit cr

foreach yvar in $compvars {
	winsor2 `yvar', cuts(.5 99.5) suffix(_w)
}

xtset firm_id fyear
gen f2020_salary_cut1 = 2020.fyear#i1.dcut_all
	replace f2020_salary_cut1 = 0 if missing(f2020_salary_cut1)


//  -----------------------------------------
//  CPS - CEO Pay Slice
summ tdc1_cps if fyear==2020 & mainsample==1, detail
// histogram tdc1_cps if fyear==2020 & mainsample==1, bin(50)
capture drop cps_d f2020_cps0 f2020_cps1
summ tdc1_cps if fyear==2019 & mainsample==1, detail
gen cps_d = 1 if (l1.tdc1_cps<`r(p50)') & fyear==2020 & mainsample==1
replace cps_d = 0 if missing(cps_d) & fyear==2020 & mainsample==1

summ tdc1_cps if cps_d == 1 & fyear==2020 & mainsample==1
summ tdc1_cps if cps_d == 0 & fyear==2020 & mainsample==1

gen f2020_cps0 = i1.f2020_salary_cut1#i0.cps_d
	replace f2020_cps0 = 0 if missing(f2020_cps0)
tab fyear f2020_cps0 if mainsample==1
gen f2020_cps1 = i1.f2020_salary_cut1#i1.cps_d
	replace f2020_cps1 = 0 if missing(f2020_cps1)
tab fyear f2020_cps1 if mainsample==1

//  -----------------------------------------
//  Board independence 
capture drop isBoardInd
// histogram boardInd if fyear==2019 & mainsample==1
summ boardInd if fyear==2019 & mainsample==1, detail
gen isBoardInd = 0 if (l1.boardInd<`r(p75)') & fyear==2020 & mainsample==1
replace isBoardInd = 1 if missing(isBoardInd) & fyear==2020 & mainsample==1
tab fyear isBoardInd
	replace isBoardInd= 0 if fyear!=2020 | mainsample!=1
summ l1.boardInd if isBoardInd==0 & fyear==2020 & mainsample==1
summ l1.boardInd if isBoardInd==1 & fyear==2020 & mainsample==1

capture drop f2020_ind0 f2020_ind1
gen f2020_ind0 = i1.f2020_salary_cut1#i0.isBoardInd
	replace f2020_ind0 = 0 if missing(f2020_ind0)
tab fyear f2020_ind0 if mainsample==1
gen f2020_ind1 = i1.f2020_salary_cut1#i1.isBoardInd
	replace f2020_ind1 = 0 if missing(f2020_ind1)
tab fyear f2020_ind1 if mainsample==1

//  -----------------------------------------
//  Board experience
capture drop isExp
// histogram priorBoards if fyear==2019 & mainsample==1
summ priorBoards if fyear==2019 & mainsample==1, detail
gen isExp = 0 if (l1.priorBoards<`r(p75)') & fyear==2020 & mainsample==1
replace isExp = 1 if missing(isExp) & fyear==2020 & mainsample==1
tab fyear isExp
	replace isExp= 0 if fyear!=2020 | mainsample!=1
summ l1.priorBoards if isExp==0 & fyear==2020 & mainsample==1
summ l1.priorBoards if isExp==1 & fyear==2020 & mainsample==1

capture drop f2020_exp0 f2020_exp1
gen f2020_exp0 = i1.f2020_salary_cut1#i0.isExp
	replace f2020_exp0 = 0 if missing(f2020_exp0)
tab fyear f2020_exp0 if mainsample==1
gen f2020_exp1 = i1.f2020_salary_cut1#i1.isExp
	replace f2020_exp1 = 0 if missing(f2020_exp1)
tab fyear f2020_exp1 if mainsample==1

//  -----------------------------------------
//  Board tenure
capture drop isBoardEst
// histogram boardInd if fyear==2019 & mainsample==1
summ nedTenure if fyear==2019 & mainsample==1, detail
gen isBoardEst = 1 if (l1.nedTenure>`r(p75)') & fyear==2020 & mainsample==1
replace isBoardEst = 0 if missing(isBoardEst) & fyear==2020 & mainsample==1
tab fyear isBoardEst
	replace isBoardEst= 0 if fyear!=2020 | mainsample!=1
summ l1.nedTenure if isBoardEst==0 & fyear==2020 & mainsample==1
summ l1.nedTenure if isBoardEst==1 & fyear==2020 & mainsample==1

capture drop f2020_est0 f2020_est1
gen f2020_est0 = i1.f2020_salary_cut1#i0.isBoardEst
	replace f2020_est0 = 0 if missing(f2020_est0)
tab fyear f2020_est0 if mainsample==1
gen f2020_est1 = i1.f2020_salary_cut1#i1.isBoardEst
	replace f2020_est1 = 0 if missing(f2020_est1)
tab fyear f2020_est1 if mainsample==1

//  -----------------------------------------
//  Busy boards
capture drop isBusy
// histogram othBoardLst if fyear==2019 & mainsample==1
// summ othBoardAll if fyear==2019 & mainsample==1, detail
gen othRatio = othBoardLst / boardSize
summ othBoardLst if fyear==2019 & mainsample==1, detail
summ othRatio if fyear==2019 & mainsample==1, detail
gen isBusy = 0 if (l1.othBoardLst>=`r(p75)') & fyear==2020 & mainsample==1
replace isBusy = 1 if missing(isBusy) & fyear==2020 & mainsample==1
tab fyear isBusy
	replace isBusy= 0 if fyear!=2020 | mainsample!=1
summ l1.othBoardLst if isBusy==0 & fyear==2020 & mainsample==1
summ l1.othBoardLst if isBusy==1 & fyear==2020 & mainsample==1

capture drop f2020_bus0 f2020_bus1
gen f2020_bus0 = i1.f2020_salary_cut1#i0.isBusy
	replace f2020_bus0 = 0 if missing(f2020_bus0)
tab fyear f2020_bus0 if mainsample==1
gen f2020_bus1 = i1.f2020_salary_cut1#i1.isBusy
	replace f2020_bus1 = 0 if missing(f2020_bus1)
tab fyear f2020_bus1 if mainsample==1


//  -----------------------------------------

cls
#delimit ;
global salaryCutMain0415
	ln_mcap btm leverage_mkt tangibility ret_std roa_std xrd_at
	payout_d boardSize boardTenure prc_delta exret_202012
; #delimit cr

capture drop tdc1_wm
	gen tdc1_wm = tdc1_w / 1000

foreach iter in cps ind exp est bus {

di "----------------------"
di "Processing: `iter'"
di "----------------------"
local xvar ""
if inlist("`iter'","cps") local xvar f2020_cps0 f2020_cps1
if inlist("`iter'","ind") local xvar f2020_ind0 f2020_ind1
if inlist("`iter'","exp") local xvar f2020_exp0 f2020_exp1
if inlist("`iter'","est") local xvar f2020_est0 f2020_est1
if inlist("`iter'","bus") local xvar f2020_bus0 f2020_bus1

foreach yvar in salary bonus stock_awards_fv option_awards_fv noneq_incent othcomp {

local fix f2020 if inrange(fyear,2019,2020) & mainsample==1, a(firm_id) vce(cluster firm_id)

eststo gov_`iter'_`yvar':  reghdfe `yvar'_fr `xvar' $salaryCutMain0415 i.firm_fe `fix'
	estadd local fmfe = "\multicolumn{1}{c}{Yes}"
	if inlist("`iter'","cps") lincom _b[f2020_cps0] - _b[f2020_cps1]
	if inlist("`iter'","idx") lincom _b[f2020_gov0] - _b[f2020_gov1]
	if inlist("`iter'","ind") lincom _b[f2020_ind0] - _b[f2020_ind1]
	if inlist("`iter'","bus") lincom _b[f2020_bus0] - _b[f2020_bus1]
	if inlist("`iter'","exp") lincom _b[f2020_exp0] - _b[f2020_exp1]
	if inlist("`iter'","est") lincom _b[f2020_est0] - _b[f2020_est1]
		qui estadd scalar comb_c = r(estimate)
		qui estadd scalar comb_t = r(t)


//  Dollar value regressions
capture drop `yvar'_wm
	gen `yvar'_wm = `yvar'_w / 1000
eststo govw_`iter'_`yvar': qui reghdfe `yvar'_wm `xvar' tdc1_wm $salaryCutMain0415 i.firm_fe `fix'
	if inlist("`iter'","cps") lincom _b[f2020_cps0] - _b[f2020_cps1]
	if inlist("`iter'","idx") lincom _b[f2020_gov0] - _b[f2020_gov1]
	if inlist("`iter'","ind") lincom _b[f2020_ind0] - _b[f2020_ind1]
	if inlist("`iter'","bus") lincom _b[f2020_bus0] - _b[f2020_bus1]
	if inlist("`iter'","exp") lincom _b[f2020_exp0] - _b[f2020_exp1]
	if inlist("`iter'","est") lincom _b[f2020_est0] - _b[f2020_est1]

		qui estadd scalar comb_c = r(estimate)
		qui estadd scalar comb_t = r(t)

}
}


#delimit ;
global complayout0415
	, b(%8.3f) t(%8.3f) star(* 0.10 ** 0.05 *** 0.01)
	nonotes stats(comb_c comb_t r2_a N_full,
				layout(@ (@) @ @)
				fmt(%8.3f %8.3f %8.3f %8.0fc)
				labels("Difference" " " "Adjusted R2" "Observations"))
	indicate(	"Controls = $salaryCutMain0415 *firm_fe _cons")
; #delimit cr

/*  ------------------------------------------------------------------------  */
//  Show results 

// CEO Pay Slice and CEO compensation outcomes
esttab gov_cps_* $complayout0415 nogap

// Board independence and CEO compensation outcomes
esttab gov_ind_* $complayout0415 nogap

// Board experience and CEO compensation outcomes
esttab gov_exp_* $complayout0415 nogap

// Board tenure and CEO compensation outcomes
esttab gov_est_* $complayout0415 nogap

// Busy boards and CEO compensation outcomes
esttab gov_bus_* $complayout0415 nogap

/*  -|----------------------------------------------------------------------  */
/*  ||  ---    Program end: a02-09-governance.do                              */
/*  -|  ---    Attila Balogh    --------------------------------------------  */